package com.itheima.exception;

import com.itheima.common.response.ResponseResult;
import com.itheima.common.response.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 * @作者 itcast
 * @创建日期 2020/10/12 17:51
 **/
@ControllerAdvice  // controller增强注解
public class ExceptionConfig {
    @ExceptionHandler(BusinessExcetion.class)
    @ResponseBody
    public ResponseResult exceptionHandle1(BusinessExcetion e){
        ResponseResult responseResult = e.getResponseResult();
        if(responseResult !=null){
            return responseResult;
        }
        return ResponseResult.errorResult(StatusCode.SERVER_ERROR);
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult exceptionHandle(Exception e){
        return ResponseResult.errorResult(StatusCode.SERVER_ERROR);
    }



}
